
/**
 * Module dependencies
 */

var express = require('express'),
  routes = require('./routes'),
  api = require('./routes/api'),
  http = require('http'),
  path = require('path');

var app = module.exports = express();


/**
 * Configuration
 */

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.static(path.join(__dirname, 'public')));
app.use(app.router);

// development only
if (app.get('env') === 'development') {
  app.use(express.errorHandler());
}

// production only
if (app.get('env') === 'production') {
  // TODO
};


/**
 * Routes
 */

// serve index and view partials
app.get('/', routes.index);
app.get('/partials/:name', routes.partials);
app.get('/pepes/:id', routes.pepes);

// JSON API
app.get('/api/name', api.name);
app.get('/api/listPersonas', api.listPersonas);
app.get('/api/getPersonas/:id', api.getPersonas);
app.post('/api/addPersonas', api.addPersonas);
app.put('/api/updatePersonas', api.updatePersonas);
app.del('/api/deletePersonas/:id', api.deletePersonas);
//asignaturas
app.get('/api/listAsignaturas', api.listAsignaturas);
app.get('/api/getAsignaturas/:id', api.getAsignaturas);
app.post('/api/addAsignaturas', api.addAsignaturas);
app.put('/api/updateAsignaturas', api.updateAsignaturas);
app.del('/api/deleteAsignaturas/:id', api.deleteAsignaturas);
//notas
app.get('/api/listNotas', api.listNotas);
app.get('/api/getNotas/:id', api.getNotas);
app.post('/api/addNotas', api.addNotas);
app.put('/api/updateNotas', api.updateNotas);
app.del('/api/deleteNotas/:id', api.deleteNotas);


// redirect all others to the index (HTML5 history)
//app.get('*', routes.index);


/**
 * Start Server
 */

http.createServer(app).listen(app.get('port'), function () {
  console.log('Express server listening on port ' + app.get('port'));
});
